package com.rockcent.mall.lib.helper;

import com.rockcent.mall.lib.domain.MerchantOrder;
import com.rockcent.mall.lib.domain.OrderEvent;
import com.rockcent.mall.lib.domain.enumclass.OrderEventType;
import com.rockcent.mall.lib.repository.OrderEventRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by DK on 16/11/16.
 */
@Component
public class OrderEventHelper {

    @Autowired
    private OrderEventRepository orderEventRepository;

    /**
     * 订单事件记录
     * @param merchantOrder 订单记录
     * @param eventType 备注
     * @param operator 操作人
     */
    public void saveOrderEvent(MerchantOrder merchantOrder, OrderEventType eventType, String operator, Long operatorId){
        OrderEvent orderEvent = new OrderEvent();
        orderEvent.setMallOrderNum(merchantOrder.getMallOrderNum());
        orderEvent.setMallId(merchantOrder.getMallId());
        orderEvent.setRemark(eventType.getValue());
        orderEvent.setMerchantId(merchantOrder.getMerchantId());
        orderEvent.setMerchantOrderNum(merchantOrder.getOrderNum());
        orderEvent.setOperator(operator);
        orderEvent.setOperatorId(operatorId);
        orderEvent.setEventType(eventType);
        orderEventRepository.save(orderEvent);
    }
}
